package cn.sm1234.dao;

import cn.sm1234.domain.Emp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.io.Serializable;
import java.util.List;

/*
* JpaRepository提供的常用接口
* 1）Repository
* 提供了基于方法名字的查询
* 2)CrudRepository
* 3)PagingAndSortingRepository
* 4)JpaRepsitory
* 5)JPASpecificationExcutor
* */
public interface  EmpRepository  extends CrudRepository<Emp, Serializable> {

    /*基于（Emp模型类）方法名称查询*/
    // 查询name()
    public List<Emp> findByName(String name);
    public List<Emp> findByNameAndGender(String name, String gender);
    public List<Emp> findByTelephoneLike(String telephone);


    // query 查询, 也是基于(Emp模型类)
    @Query("from Emp where name = ?")
    public List<Emp> querName(String name);

    // 这里使用原生SQL
    @Query(value = "select * from t_emp where name = ?", nativeQuery = true)
    public List<Emp> querName2(String name);

    //QUERY 操作
    @Query("update Emp set address = ?  WHERE id = ?")
    @Modifying
    public void updateAddressById(String address, Integer id);
}


